﻿CREATE PROCEDURE [security].[spValidaUsuario]
	@psUserName			NVARCHAR(20),
	@psPassword			NVARCHAR(200)
AS
BEGIN
	DECLARE @KEYID UNIQUEIDENTIFIER
	DECLARE @sPass NVARCHAR(200)
	SET @KEYID = KEY_GUID('SYM_KEY')
	 
	OPEN SYMMETRIC KEY SYM_KEY
	DECRYPTION BY PASSWORD='##SACM12##'
 
	SELECT @sPass = DECRYPTBYKEY([Password]) FROM security.CatUsuario WHERE UserName = @psUserName
	--SELECT @sPass
	CLOSE SYMMETRIC KEY SYM_KEY
	
	IF EXISTS(SELECT 1 FROM security.CatUsuario WHERE @sPass = @psPassword AND UserName = @psUserName and IdEstatus = 1)
	BEGIN
		SELECT 1 TienePermiso
	END
	ELSE
	BEGIN
		SELECT 0 TienePermiso
		--RAISERROR('Nombre de usuario o contraseña incorrecta',16,1)
	END
END